package friend

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"project-im/config"
	"project-im/internal/api/response"
	"project-im/internal/model/dao"
)

func FriendList(c *gin.Context) {
	value, _ := c.Get("userId")
	var friend []dao.ImFriend
	var friends []*response.Friends
	config.DB.Where("user_id=?", value).Find(&friend)
	for _, imFriend := range friend {
		friends = append(friends, &response.Friends{
			ID:        imFriend.ID,
			NickName:  imFriend.FriendNickName,
			HeadImage: imFriend.FriendHeadImage,
		})
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "查询成功",
		"data": friends,
	})
}
